clear all 
log using "/Users/abhram/Library/CloudStorage/Dropbox/Research/trA/replication/table_2.log", replace 

	
******************************************************************** 
********          TABLE 2:  POOLED IVQR                     ********
******************************************************************** 
	



	use "Duranton_Turner_AER_2010.dta", clear


	* Selection of observations
	drop if l_ln_km_IH_83==0

	rename sprawl_1992 sprawl_1993
	rename sprawl_1976 sprawl_1983
	gen sprawl_2003 = sprawl_1993

	*rescale so display is better
	replace elevat_range_msa = elevat_range_msa/1000 
	replace ruggedness_msa = ruggedness_msa/1000
	replace heating_dd = heating_dd/100
	replace cooling_dd = cooling_dd/100

      rename S_somecollege_80 S_somecollege_1983
      rename S_somecollege_00 S_somecollege_2003
      rename S_somecollege_90 S_somecollege_1993
      rename S_poor_80 S_poor_1983
      rename S_poor_90 S_poor_1993
      rename S_poor_00 S_poor_2003
      rename l_mean_income_80 l_mean_income_1983
      rename l_mean_income_90 l_mean_income_1993
      rename l_mean_income_00 l_mean_income_2003
      rename S_manuf83 S_manuf_1983
      rename S_manuf93 S_manuf_1993
      rename S_manuf03 S_manuf_2003
      rename S_truck83 S_truck_1983
      rename S_truck93 S_truck_1993
      rename S_truck03 S_truck_2003
      gen l_pop_1983 = l_pop80 
      gen l_pop_1993 = l_pop90 
      gen l_pop_2003 = l_pop00 

      rename l_max_84bus l_bus_1983 
      rename l_max_94bus l_bus_1993 
      rename l_max_04bus l_bus_2003 
      rename l_transit84 l_transit_1983
      rename l_transit94 l_transit_1993 
      rename l_transit04 l_transit_2003

      rename l_ln_km_IHU_83 l_ln_km_IHU_1983
      rename l_ln_km_IHU_93 l_ln_km_IHU_1993
      rename l_ln_km_IHU_03 l_ln_km_IHU_2003
      rename l_ln_km_IH_83 l_ln_km_IH_1983
      rename l_ln_km_IH_93 l_ln_km_IH_1993
      rename l_ln_km_IH_03 l_ln_km_IH_2003
      rename l_ln_km_MRU_83 l_ln_km_MRU_1983
      rename l_ln_km_MRU_93 l_ln_km_MRU_1993
      rename l_ln_km_MRU_03 l_ln_km_MRU_2003
      
      rename l_vmt_IHU_83 l_vmt_IHU_1983
      rename l_vmt_IHU_93 l_vmt_IHU_1993
      rename l_vmt_IHU_03 l_vmt_IHU_2003
      rename l_vmt_IH_83 l_vmt_IH_1983
      rename l_vmt_IH_93 l_vmt_IH_1993
      rename l_vmt_IH_03 l_vmt_IH_2003
      rename l_vmt_MRU_83 l_vmt_MRU_1983
      rename l_vmt_MRU_93 l_vmt_MRU_1993
      rename l_vmt_MRU_03 l_vmt_MRU_2003



	reshape long l_ln_km_IH  l_ln_km_IHU  l_ln_km_IHNU  l_ln_km_MRU l_vmt_IH l_vmt_IHU  l_vmt_IHNU  l_vmt_MRU l_bus l_transit sprawl S_somecollege l_mean_income S_poor S_manuf S_truck l_pop, i(msa ) j(year _1983 _1993 _2003)

	local geography	 "elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl"
	local demographics "S_somecollege l_mean_income S_poor S_manuf"  
	local census_div "div1 div2 div3 div4 div5 div6 div7 div8 div9"
	local population "l_pop80 l_pop70 l_pop60 l_pop50 l_pop40 l_pop30 l_pop20"  


	
* First Panel *	
		
		local Inst "l_rail1898 l_hwy1947 l_pix1835"
		capture drop l_vmt l_ln
		gen l_vmt = l_vmt_IH  
		gen l_ln  = l_ln_km_IH 



* Model 1 *	

		xi: ivregress 2sls l_vmt i.year (l_ln = l_rail1898 l_hwy1947 l_pix1835), robust      

		xi: ivqregress iqr l_vmt i.year (l_ln = l_rail1898 l_hwy1947 l_pix1835) ,  quantile(10 25 50 75 90) bound(0 5, at(0.25)) vce(robust) 

		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 
		estat coefplot, name (ivqr_pooled_panel_1_model_1, replace) subtitle (Model 1)
		

* Model 2 *	

		xi: ivregress 2sls l_vmt l_pop i.year  (l_ln = l_rail1898 l_hwy1947 l_pix1835), robust      		

		xi: ivqregress iqr l_vmt l_pop i.year (l_ln = l_rail1898 l_hwy1947 l_pix1835) ,  quantile(10 25 50 75 90) vce(robust)  
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 
		estat coefplot, name (ivqr_pooled_panel_1_model_2, replace) subtitle (Model 2)



* Model 3 *	

		xi: ivregress 2sls l_vmt l_pop div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year  (l_ln = l_rail1898 l_hwy1947 l_pix1835), robust      			
		
		xi: ivqregress iqr l_vmt l_pop div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln = l_rail1898 l_hwy1947 l_pix1835) ,  quantile(10 25 50 75 90) vce(robust)        
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 
		estat coefplot, name (ivqr_pooled_panel_1_model_3, replace) title(.)  ytitle(Elasticity of VMT to interstate highway capacity) 
		
		graph export "/Users/abhram/Library/CloudStorage/Dropbox/Research/trA/replication/pooled_ivqr_model3.pdf", replace



* Model 4 *	

		xi: ivregress 2sls l_vmt l_pop S_somecollege l_mean_income S_poor S_manuf div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln = l_rail1898 l_hwy1947 l_pix1835), robust      			
		
		xi: ivqregress iqr l_vmt l_pop S_somecollege l_mean_income S_poor S_manuf div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln = l_rail1898 l_hwy1947 l_pix1835) ,  quantile(10 25 50 75 90)   vce(robust)        
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 
		estat coefplot, name (ivqr_pooled_panel_1_model_4, replace) subtitle (Model 4)



* Model 5 *	

		xi: ivregress 2sls l_vmt l_pop l_pop80 l_pop70 l_pop60 l_pop50 l_pop40 l_pop30 l_pop20 S_somecollege l_mean_income S_poor S_manuf div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln = l_rail1898 l_hwy1947 l_pix1835), robust       				
		
		xi: ivqregress iqr l_vmt l_pop l_pop80 l_pop70 l_pop60 l_pop50 l_pop40 l_pop30 l_pop20 S_somecollege l_mean_income S_poor S_manuf div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln = l_rail1898 l_hwy1947 l_pix1835) ,  quantile(10 25 50 75 90) vce(robust)  
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 
		estat coefplot, name (ivqr_pooled_panel_1_model_5, replace) subtitle (Model 5)
		
		

		*graph combine ivqr_pooled_panel_1_model_1 ivqr_pooled_panel_1_model_2 ivqr_pooled_panel_1_model_3 ivqr_pooled_panel_1_model_4 ivqr_pooled_panel_1_model_5, xcommon ycommon altshrink title("Pooled IVQR estimates of elasticity of aggregate MSA VMT to IH lane miles") note("Note: The graphs are analogous to the first panel of Table 2 ") 
		
		*graph export "/Users/abhram/Library/CloudStorage/Dropbox/Research/trA/replication/pooled_ivqr.pdf", replace 	

	
	
	
* Second Panel *	
		
		local Inst "l_hwy1947"
		capture drop l_vmt l_ln
		gen l_vmt = l_vmt_IH  
		gen l_ln  = l_ln_km_IH 



* Model 1 *	

		xi: ivregress 2sls l_vmt i.year (l_ln =  l_hwy1947 ), robust    
		
		xi: ivqregress iqr l_vmt i.year (l_ln =  l_hwy1947 ) ,  quantile(10 25 50 75 90) vce(robust)    
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 



* Model 2 *	

		xi: ivregress 2sls l_vmt l_pop i.year  (l_ln =  l_hwy1947 ), robust      		

		xi: ivqregress iqr l_vmt l_pop i.year (l_ln =  l_hwy1947 ) ,  quantile(10 25 50 75 90) vce(robust)   
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 


* Model 3 *	

		xi: ivregress 2sls l_vmt l_pop div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year  (l_ln =  l_hwy1947 ), robust      				
		
		xi: ivqregress iqr l_vmt l_pop div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln =  l_hwy1947 ) ,  quantile(10 25 50 75 90) bound(0 4) vce(robust)  
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 



* Model 4 *	

		xi: ivregress 2sls l_vmt l_pop S_somecollege l_mean_income S_poor S_manuf div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln =  l_hwy1947 ), robust      				
		
		xi: ivqregress iqr l_vmt l_pop S_somecollege l_mean_income S_poor S_manuf div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln =  l_hwy1947 ) ,  quantile(10 25 50 75 90) vce(robust)      
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 



* Model 5 *	

		xi: ivregress 2sls l_vmt l_pop l_pop80 l_pop70 l_pop60 l_pop50 l_pop40 l_pop30 l_pop20 S_somecollege l_mean_income S_poor S_manuf div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln =  l_hwy1947 ), robust       
		
		xi: ivqregress iqr l_vmt l_pop l_pop80 l_pop70 l_pop60 l_pop50 l_pop40 l_pop30 l_pop20 S_somecollege l_mean_income S_poor S_manuf div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln =  l_hwy1947 ) ,  quantile(10 25 50 75 90)	vce(robust)
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 
	

	
	
* Third Panel *	
		
		local Inst "l_rail1898"
		capture drop l_vmt l_ln
		gen l_vmt = l_vmt_IH  
		gen l_ln  = l_ln_km_IH 



* Model 1 *	

		xi: ivregress 2sls l_vmt i.year (l_ln =  l_rail1898 ), robust   

		xi: ivqregress iqr l_vmt i.year (l_ln =  l_rail1898 ) ,  quantile(10 25 50 75 90) bound(1 2) vce(robust) 
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 



* Model 2 *	

		xi: ivregress 2sls l_vmt l_pop i.year  (l_ln =  l_rail1898 ), robust    

		xi: ivqregress iqr l_vmt l_pop i.year (l_ln =  l_rail1898 ) ,  quantile(10 25 50 75 90) vce(robust) 
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 
		


* Model 3 *	

		xi: ivregress 2sls l_vmt l_pop div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year  (l_ln =  l_rail1898 ), robust      				
		
		xi: ivqregress iqr l_vmt l_pop div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln =  l_rail1898 ) ,  quantile(10 25 50 75 90) vce(robust) 
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 
		


* Model 4 *	

		xi: ivregress 2sls l_vmt l_pop S_somecollege l_mean_income S_poor S_manuf div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln =  l_rail1898 ), robust      				
		
		xi: ivqregress iqr l_vmt l_pop S_somecollege l_mean_income S_poor S_manuf div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln =  l_rail1898 ) ,  quantile(10 25 50 75 90) vce(robust)       
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 



* Model 5 *	

		xi: ivregress 2sls l_vmt l_pop l_pop80 l_pop70 l_pop60 l_pop50 l_pop40 l_pop30 l_pop20 S_somecollege l_mean_income S_poor S_manuf div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln =  l_rail1898 ), robust      
		
		xi: ivqregress iqr l_vmt l_pop l_pop80 l_pop70 l_pop60 l_pop50 l_pop40 l_pop30 l_pop20 S_somecollege l_mean_income S_poor S_manuf div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln =  l_rail1898 ) ,  quantile(10 25 50 75 90)	vce(robust) 
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 
	

	
	
* Fourth Panel *	
		
		local Inst "l_pix1835"
		capture drop l_vmt l_ln
		gen l_vmt = l_vmt_IH  
		gen l_ln  = l_ln_km_IH 




* Model 1 *	

		xi: ivregress 2sls l_vmt i.year (l_ln =  l_pix1835 ), robust    

		xi: ivqregress iqr l_vmt i.year (l_ln =  l_pix1835 ) ,  quantile(10 25 50 75 90) vce(robust) 
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 
		


* Model 2 *	

		xi: ivregress 2sls l_vmt l_pop i.year (l_ln =  l_pix1835 ), robust  

		xi: ivqregress iqr l_vmt l_pop i.year (l_ln =  l_pix1835 ) ,  quantile(10 25 50 75 90) bound(-2 1.5) vce(robust) 
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 
      	


* Model 3 *	

		xi: ivregress 2sls l_vmt l_pop div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year  (l_ln =  l_pix1835 ), robust      				
		
		xi: ivqregress iqr l_vmt l_pop div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln =  l_pix1835 ) ,  quantile(10 25 50 75 90) bound(-1 3.5, at(0.9)) vce(robust)
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 
		


* Model 4 *	

		xi: ivregress 2sls l_vmt l_pop S_somecollege l_mean_income S_poor S_manuf div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln =  l_pix1835 ), robust      				
		
		xi: ivqregress iqr l_vmt l_pop S_somecollege l_mean_income S_poor S_manuf div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln =  l_pix1835 ) ,  quantile(10 25 50 75 90) bound(0 1, at(0.1)) vce(robust, kernel(gaussian) bwidth(bofinger)) 
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 



* Model 5 *	

		xi: ivregress 2sls l_vmt l_pop l_pop80 l_pop70 l_pop60 l_pop50 l_pop40 l_pop30 l_pop20 S_somecollege l_mean_income S_poor S_manuf div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln =  l_pix1835 ), robust       				
		
		xi: ivqregress iqr l_vmt l_pop l_pop80 l_pop70 l_pop60 l_pop50 l_pop40 l_pop30 l_pop20 S_somecollege l_mean_income S_poor S_manuf div2 div3 div4 div5 div6 div7 div8 div9 elevat_range_msa ruggedness_msa heating_dd cooling_dd sprawl i.year (l_ln =  l_pix1835 ) ,  quantile(10 25 50 75 90)	ngrid(100) vce(robust) 
		
		estat endogeffects, rseed(123456789) 
		estat endogeffects, rseed(123456789) level(90) 
	

		

log off 
